﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

using Microsoft.Phone.Tasks;
using AMobiSDK;

namespace Sai_Se_Dung
{
    public partial class LevelUp : PhoneApplicationPage
    {
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (Option.isOn == true)
            {
                mp3_levelup.AutoPlay = true;
                mp3_levelup.Play();
            }
            else
            {
                mp3_levelup.AutoPlay = false;
                mp3_levelup.Stop();
            }

            AdManager.setWidgetCode("f2257ad5570a4a773a2edd33504ef3c2");//Bạn phải thay mã này bằng widgetCode của bạn
            AdManager advertisement = new AdManager();
            advertisement.OnNavigationTo(this, null, null, banner);
        }

        public LevelUp()
        {
            InitializeComponent();
            txtLevelUpNum.Text = Play.m_curLevel.ToString();
            txtLevelUpScore.Text = Play.m_curScore.ToString();
        }

        private void btnRateApp_Click(object sender, RoutedEventArgs e)
        {
            // Not recommend code here
            // Let's synchronous MVVM & Code behind
            
            if (Option.isOn == true)
            {
                mp3_btn.Play();
            }

            MessageBox.Show("Cảm ơn bạn đã quan tâm game!", "Tiếp tục thôi nào >>>", MessageBoxButton.OK);

            Play.m_timer.Stop();
            Play.m_num = 1;
            Play.m_level += 1;

            switch (Play.m_level)
            {
                case 2:
                    Play.m_time = 6;
                    break;
                case 3:
                    Play.m_time = 75;
                    break;
            }
            NavigationService.Navigate(new Uri("/Play.xaml", UriKind.Relative));
        }

        private void btnContinue_Click(object sender, RoutedEventArgs e)
        {
            if (Option.isOn == true)
            {
                mp3_btn.Play();
            }

            MessageBox.Show("Ủng hộ 5 sao nếu thấy vui nhé.", "Bạn khá đấy!", MessageBoxButton.OK);
           
            MarketplaceReviewTask rate = new MarketplaceReviewTask();
            rate.Show();
        }

        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            if (Option.isOn == true)
            {
                mp3_btn.Play();
            }

            new Play().SetCurrentLevel();

            Play.isBacked = false;

            if (NavigationService.CanGoBack)
            {
                while (NavigationService.RemoveBackEntry() != null)
                {
                    NavigationService.RemoveBackEntry();
                }
            }
            NavigationService.Navigate(new Uri("/Confirm.xaml", UriKind.Relative));
        }
    }
}